package com.ruoyi.aitcommon.api;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.aitcommon.anotation.ApiLog;
import com.ruoyi.aitcommon.service.TaskService;
import com.ruoyi.aitcommon.utils.JSONResult;

@RestController
@RequestMapping("/ait/common/task")
public class TaskOperation {
	@Autowired
	TaskService taskService;

	@ApiLog("Task手工触发")
	@GetMapping("/run")
	public JSONObject run(String codestr) {
		if (StringUtils.isBlank(codestr))
			return JSONResult.error("参数code为空!");
		String[] codearr = codestr.split(",");
		try {
			for (String code : codearr) {
				taskService.run(Long.parseLong(code));
			}
		} catch (Exception ex) {
			return JSONResult.error(ex.getMessage());
		}
		return JSONResult.success("异步调用成功!");
	}
}
